package org.yzh.web.mp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.yzh.protocol.commons.transform.attribute.AlarmADAS;
import org.yzh.web.mp.entity.Alarm64;
import org.yzh.web.mp.mapper.TaosAlarm64Mapper;
import org.yzh.web.mp.service.TaosAlarm64Service;

/**
 * @author nick
 * @description 64报警ServiceImpl
 * @date 2022/6/14
 **/
@Service
@AllArgsConstructor
public class TaosAlarm64ServiceImpl extends ServiceImpl<TaosAlarm64Mapper, Alarm64> implements TaosAlarm64Service {

    private final TaosAlarm64Mapper alarm64Mapper;

    @Override
    public Boolean insert(Alarm64 model) {
        return alarm64Mapper.insertOne(model) > 0;
    }


//    /**
//     * 获取64报警的类型（高级驾驶辅助）
//     *
//     * @param item T0200
//     * @return 报警类型
//     */
//    @Override
//    public CloudAlarm6465InfoModel getAlarm64Type(T0200 item) {
//        if (item.getAttributes().get(SysConst.ATTRIBUTE_ADAS_INDEX) != null) {
//            CloudAlarm6465InfoModel alarm6465InfoModel = new CloudAlarm6465InfoModel();
//            AlarmADAS adas = (AlarmADAS) item.getAttributes().get(SysConst.ATTRIBUTE_ADAS_INDEX);
//            alarm6465InfoModel.setEventType(adas.getType());
//            alarm6465InfoModel.setAttachments(adas.getFileTotal());
//            alarm6465InfoModel.setAlarmId(String.valueOf(adas.getId()));
//            alarm6465InfoModel.setAlarmLevel(adas.getLevel());
//            return alarm6465InfoModel;
//        }
//        return null;
//    }


    /**
     * 插入64报警（ADAS）
     *
     * @param vehicleId 车辆id
     * @param alarmAdas Adas实体
     */
    @Override
    public void insertAlarm64(String vehicleId, AlarmADAS alarmAdas) {
        // TD adas报警
        this.insert(this.toAlarm64(alarmAdas, vehicleId));
    }


    private Alarm64 toAlarm64(AlarmADAS alarmAdas, String vehicleId) {
        // TD adas报警
        Alarm64 alarm64 = new Alarm64();
        return alarm64.populateAlarmFields(vehicleId, alarmAdas.getType(), alarmAdas.getLevel(), alarmAdas.getId(), alarmAdas.getFileTotal(), alarmAdas.getDateTime(), alarmAdas.getLongitude() / 1000000.0, alarmAdas.getLatitude() / 1000000.0, alarm64);

    }


}
